#ifndef __LM_AV_COMM_H__
#define __LM_AV_COMM_H__

#include <vector>

#ifndef __cplusplus
extern "C"
{
#endif

#include "lm_avnet_base.h"
#include "lmCommon.h"


#define MAX_PARSE_SIZE0  327680 //(320 * 1024)
#define MAX_PARSE_SIZE1  30720  //(30 * 1024)

typedef enum
{
	MD_FILE = 0,
	MD_KIVE,
	MD_MAX,
}stmode_em;;


class LmShareBuff;
class LmFileParse;

typedef std::vector<LmFileParse*>FileParse_vector;

class LmAvSimulate
{
	public:
		LmAvSimulate();
		~LmAvSimulate();

	public:	
		int av_comm_init(int fileNum, file_st *files[]);
		int GetStream(Frame_st *&pFrame);
		int DoProductePth();

	private:
		FileParse_vector  m_FileParse_vect;
		pthread_t         m_streamProducePth;
		int               m_readerId;

		LmShareBuff    *m_shareBuff;
};


class LmFileParse
{
	public:
		LmFileParse();
		virtual ~LmFileParse();

		virtual int lmDoParse(LmShareBuff *pShareBuff, int streamNum=0) = 0;
		
	public:
		file_rec_st *m_fileRec;
		file_st 	*m_file;	
		char   	    *m_buff;
};


class LmEsFileParse : public LmFileParse
{
	public:
		LmEsFileParse(file_st 	  *file);
		~LmEsFileParse();

	private:
		virtual int lmDoParse(LmShareBuff *pShareBuff, int streamNum=0);

		int get_nalu_type(uchar fmt, int sqe, char *data, uchar *type);
		uint rmove_h264or5_eb(uchar* to, int u_sz, uchar* from, uint fr_sz);//emulation_bytes filter.

	private:
		VFrameInf_st  *m_vframeInf; 
		uint           m_timestate;
};

class LmAacFileParse : public LmFileParse
{
	public:
		LmAacFileParse(file_st     *file);
		~LmAacFileParse();

	protected:
		virtual int lmDoParse(LmShareBuff *pShareBuff, int streamNum=0);
		int spare_aac(FILE *fd, aac_st *aac);

	private:
		av_inf_st	*m_avinf;

};


class LmG711FileParse : public LmFileParse
{
	public:
		LmG711FileParse(file_st 	 *file);
		~LmG711FileParse();
		
	private:
		virtual int lmDoParse(LmShareBuff *pShareBuff, int streamNum=0);

	private:
		uint     m_timestate;
};

class LmPcmFileParse : public LmFileParse
{
	public:
		LmPcmFileParse(file_st     *file);
		~LmPcmFileParse();
		
	private:
		virtual int lmDoParse(LmShareBuff *pShareBuff, int streamNum=0);

};


#ifndef __cplusplus
}
#endif

#endif
